package com.dinggou.shopjb.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.dinggou.shopjb.R;
import com.dinggou.shopjb.bean.RedBagBean;

import java.util.ArrayList;
import java.util.List;

public class RedBagRecordAdapter extends RecyclerView.Adapter<RedBagRecordAdapter.RecordHolder> {
    private List<RedBagBean> redBagBeanList = new ArrayList<>();

    public void setRedBagBeanList(List<RedBagBean> redBagBeanList) {
        this.redBagBeanList = redBagBeanList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RecordHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_redbag_record, parent, false);
        return new RecordHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecordHolder holder, int position) {
        RedBagBean redBagBean = redBagBeanList.get(position);
        holder.tv_time.setText(redBagBean.startTime + " - " + redBagBean.endTime);
        if (redBagBean.integral != null){
            holder.tv_status.setText(redBagBean.integral + "积分");
        }else {
            holder.tv_status.setText("未参与或中奖");
        }
    }

    @Override
    public int getItemCount() {
        return redBagBeanList.size();
    }

    public class RecordHolder extends RecyclerView.ViewHolder{

        private final TextView tv_time, tv_status;

        public RecordHolder(@NonNull View itemView) {
            super(itemView);
            tv_time = itemView.findViewById(R.id.tv_time);
            tv_status = itemView.findViewById(R.id.tv_status);
        }
    }
}
